import 'package:bot_toast/bot_toast.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';

import 'aiface_page.dart';
import 'package:exams_app/home_module/exams_module/logic.dart';

class TextInstructionsPage extends StatelessWidget {


  HomeModuleLogic logic = Get.put(HomeModuleLogic());


  var ksty;

  TextInstructionsPage(this.ksty);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('考试须知'),
      ),
      body: ListView(
        children: [
          Container(
            margin: EdgeInsets.only(top: 15, left: 15),
            child: Text(
              '考试须知',
              style: TextStyle(
                  fontSize: 18,
                  color: HexColor('#333333'),
                  fontWeight: FontWeight.w500),
            ),
          ),
          GetBuilder<HomeModuleLogic>(
            initState: (as){
              logic.requestDataWithApiRef();
            },
            builder: (logic) {
              return Container(
                padding: EdgeInsets.all(5),
                margin: EdgeInsets.only(top: 5, left: 15, right: 15),
                child: Text(logic.refJson['data']),
              );
            },
          ),

          Visibility(
            visible: ksty=='no'?false:true,
              child: CheckWidget()
          ),
          //
        ],
      ),
    );
  }
}


class CheckWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return CheckWidgetState();
  }
}

class CheckWidgetState extends State<CheckWidget> {


  var check = false;


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(left: 10, bottom: 50),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(top: 25, right: 10, left: 0),
            width: Get.width,
            height: 45,
            child: RaisedButton(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(22),
              ),
              color: Theme
                  .of(context)
                  .primaryColor,
              onPressed: () {
                if (check) {

                  Get.to(AiFacePage());
                  // Get.to(ExamsPage());
                  return;
                }
                BotToast.showText(text: '请勾选');
              },
              child: Text(
                '进入考试',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
          Row(
            children: [
              Checkbox(
                value: check,
                onChanged: (bool value) {
                  check = !check;
                  setState(() {

                  });
                },
              ),
              RichText(
                text:
                TextSpan(style: DefaultTextStyle
                    .of(context)
                    .style, children: [
                  TextSpan(text: '我已阅读并同意'),
                  TextSpan(

                      text: '《考试须知》',
                      style: TextStyle(color: Theme
                          .of(context)
                          .primaryColor)),
                ]),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
